package com.wn.deadLetterchange;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class LetterConfig {


    @Bean
    public Queue letterQueueA() {
        return new Queue("letterQueueA");
    }

    @Bean
    public Queue letterQueueB() {
        return QueueBuilder.durable("letterQueueB")
                .ttl(25*1000)
                .deadLetterExchange("direct_exchangeB")
                .deadLetterRoutingKey("deadletter")
                .build();
    }

    @Bean
    public Queue letterQueueC() {
        return new Queue("letterQueueC");
    }


    @Bean
    public DirectExchange DirectExchangeA() {
        return new DirectExchange("direct_exchangeA");
    }

    @Bean
    public DirectExchange directExchangeB() {
        return new DirectExchange("direct_exchangeB");
    }

    @Bean
    public Binding BindingLetter(){
        return BindingBuilder
                .bind(letterQueueA())
                .to(DirectExchangeA())
                .with("email");
    }

    @Bean
    public Binding BindingDleter(){
        return BindingBuilder
                .bind(letterQueueB())
                .to(DirectExchangeA())
                .with("dleter");
    }


    @Bean
    public Binding BindingDead(){
        return BindingBuilder
                .bind(letterQueueC())
                .to(directExchangeB())
                .with("deadletter");
    }

}
